/**  
 * @Title: GameTypeController.java
 * @Package com.limit.control.admin
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-3 上午10:29:52
 * @version V1.0
 */ 
package com.limit.control.admin;

import java.util.List;
import com.limit.model.GameType;

/** 
 * <br/>
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-3 上午10:29:52 
 * @version V1.0
 */

public class GameTypeController extends BaseController {

	public void index(){
		List<GameType> gametypes = GameType.dao.find("select * from game_type order by sort_id desc");
		this.setAttr("gametypes", gametypes);
		render("gametypes.html");
	}
	
	public void view(){
		this._commonSetId();
		GameType gametype = new GameType();
		if(id > 0){
			gametype = GameType.dao.findById(id);
		}
		this.setAttr("gametype", gametype);
		render("gametype_view.html");
		
	}

	/**
	 * 添加
	 */
	public void save(){
		GameType gametype = this.getModel(GameType.class , "gametype");
		this._validateParam(gametype);
		gametype.save();
		this.index();
		
	}

	private void _validateParam(GameType gametype) {
		boolean valiName = false , valiSort = false;
		if(gametype.getStr("name")==null || gametype.getStr("name").trim().equals("")) valiName = true;
		if(gametype.getInt("sort_id")==null || gametype.getInt("sort_id")== 0) valiSort = true;
		if(valiName || valiSort){
			if(valiName)	this.setAttr("nameError", "类型名称不能为空！");
			if(valiSort)	this.setAttr("sort_idError", "排序号不能为空！");
			this.setAttr("gametype", gametype);
			this.render("gametype_view.html");
			return ;
		}
	}
	
	/**
	 * 修改
	 */
	public void update(){
		GameType gametype = this.getModel(GameType.class , "gametype");
		this._validateParam(gametype);
		gametype.update();
		this.index();
		
		
	}
	
	/**
	 * 删除操作
	 */
	public void delete(){
		this._commonSetId();
		this.getModel(GameType.class).deleteById(id);
		this.index();
	}
		
	
}
